﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DBUtility;
using System.Collections;
using System.Data.OracleClient;
using System.Data;

namespace TierApplication
{
    /// <summary>
    /// 卡号导入临时表
    /// </summary>
    public partial class T_IMPCARD
    {
        public static void ImpData(List<T_IMPCARD> mImpCardList)
        {
            Hashtable SQLStringList = new Hashtable();
            for (int i = 0; i < mImpCardList.Count; i++)
            {
                string cmdText = "Insert Into T_ImpCard(IMPBATCHNO,CARDNO,CARDPWD,CRATEDATE) values(:IMPBATCHNO{0},:CARDNO{0},:CARDPWD{0},SysDate)";
                OracleParameter[] parameters = {
					new OracleParameter(string.Format(":IMPBATCHNO{0}",i), OracleType.VarChar,10),
					new OracleParameter(string.Format(":CARDNO{0}",i), OracleType.VarChar,30),
					new OracleParameter(string.Format(":CARDPWD{0}",i), OracleType.VarChar,90)};
                parameters[0].Value = mImpCardList[i].IMPBATCHNO;
                parameters[1].Value = mImpCardList[i].CARDNO;
                string sCardPwd = TranUtils.Encrypt(mImpCardList[i].CARDPWD);
                parameters[2].Value = sCardPwd;
                SQLStringList.Add(string.Format(cmdText, i), parameters);
            }
            try
            {
                DBUtility.DbHelperOra.ExecuteSqlTran(SQLStringList);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public static DataSet GetImpCardList(string sIMPBATCHNO)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select IMPBATCHNO,CARDNO,CARDPWD,CRATEDATE");
            strSql.Append(" FROM T_IMPCARD ");
            strSql.Append(" where IMPBATCHNO='" + sIMPBATCHNO + "'");
            return DbHelperOra.Query(strSql.ToString());
        }

        public static void DeleteImpCard(string sIMPBATCHNO)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("Delete from T_IMPCARD where IMPBATCHNO ='" + sIMPBATCHNO + "'");
            DbHelperOra.ExecuteSql(strSql.ToString());
        }


        public static void ImpPrudoctItem(string ac_impbatchno, string ac_userid,
                                          string ac_productid,
                                          double AN_PURCHASEPRICE,
                                          string ac_lifedate,
                                          ref Int32 ai_result, ref string ac_result)
        {
            OracleParameter[] parameters ={
                                 new OracleParameter("ac_impbatchno",OracleType.VarChar,10),
                                 new OracleParameter("ac_userid",OracleType.VarChar,60),
                                 new OracleParameter("ac_productid",OracleType.VarChar,20),
                                 new OracleParameter("AN_PURCHASEPRICE",OracleType.Double,10),
                                 new OracleParameter("ac_lifedate",OracleType.VarChar,8),
                                 new OracleParameter("ai_result",OracleType.Int32),
                                 new OracleParameter("ac_result",OracleType.VarChar,4000)
                                                };
            parameters[0].Value = ac_impbatchno;
            parameters[1].Value = ac_userid;
            parameters[2].Value = ac_productid;
            parameters[3].Value = AN_PURCHASEPRICE;
            parameters[4].Value = ac_lifedate;
            parameters[0].Direction = ParameterDirection.Input;
            parameters[1].Direction = ParameterDirection.Input;
            parameters[2].Direction = ParameterDirection.Input;
            parameters[3].Direction = ParameterDirection.Input;
            parameters[4].Direction = ParameterDirection.Input;
            parameters[5].Direction = ParameterDirection.Output;
            parameters[6].Direction = ParameterDirection.Output;
            try
            {
                OracleCommand cmd = DbHelperOra.RunProcedureReturnCammand("sp_Imp_Product_Item_ImpBatchNo", parameters);
                ai_result = int.Parse(cmd.Parameters["ai_result"].Value.ToString());
                ac_result = cmd.Parameters["ac_result"].Value.ToString();

            }
            catch (Exception e)
            {
                ai_result = -1;
                ac_result = "调用后台过程错误,错误原因为：" + TierService.PageValidate.RemoveChr10And13(e.Message);
            }


        }

        public static void IMP_PRODUCT_ITEM_ADUIT(string ac_impbatchno, string ac_userid, string ac_status,
                                                    ref Int32 ai_result, ref string ac_result)
        {
            OracleParameter[] parameters ={
                                               new OracleParameter("ac_impbatchno",OracleType.VarChar,10),
                                 new OracleParameter("ac_userid",OracleType.VarChar,60),
                                 new OracleParameter("ac_status",OracleType.VarChar,1),
                                  new OracleParameter("ai_result",OracleType.Int32),
                                   new OracleParameter("ac_result",OracleType.VarChar,4000)
                                                };
            // AC_STATUS 0 :提交审核  1 退回审核  2 审核 
            parameters[0].Value = ac_impbatchno;
            parameters[1].Value = ac_userid;
            parameters[2].Value = ac_status;
            parameters[0].Direction = ParameterDirection.Input;
            parameters[1].Direction = ParameterDirection.Input;
            parameters[2].Direction = ParameterDirection.Input;
            parameters[3].Direction = ParameterDirection.Output;
            parameters[4].Direction = ParameterDirection.Output;
            try
            {
                OracleCommand cmd = DbHelperOra.RunProcedureReturnCammand("SP_IMP_PRODUCT_ITEM_ADUIT", parameters);
                ai_result = int.Parse(cmd.Parameters["ai_result"].Value.ToString());
                ac_result = cmd.Parameters["ac_result"].Value.ToString();

            }
            catch (Exception e)
            {
                ai_result = -1;
                ac_result = "调用后台过程错误,错误原因为：" + TierService.PageValidate.RemoveChr10And13(e.Message);
            }


        }
    }


}